package com.yl.androidutilscenter.http.gson

import com.google.gson.Gson
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import okhttp3.ResponseBody
import retrofit2.Converter


/**
 * @author
 * @description:
 * @date :2024/4/3
 * @version 1.0.0
 */
class MyGsonResponseBodyConverter<T>(var gson: Gson, var adapter: TypeAdapter<T>) :
    Converter<ResponseBody, T> {

    override fun convert(value: ResponseBody): T? {
        val jsonReader: JsonReader = gson.newJsonReader(value.charStream())
        jsonReader.isLenient = true
        return value.use { _ ->
            adapter.read(jsonReader)
        }
    }
}